﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Samples.ServiceHosting.StorageClient;

namespace CCS
{
    public static class Extensions
    {
        public static void InitTableStorageDefaults(this TableStorageEntity entity)
        {
            IEnumerable<PropertyInfo> dates = entity.GetType().GetProperties().Where(p => p.PropertyType == typeof(DateTime));
            foreach (PropertyInfo date in dates)
            {
                date.SetValue(entity, TableStorageConstants.MinSupportedDateTime, null);
            }
        }

        public static Guid DefaultRowKey()
        {
            return Guid.NewGuid();
        }

        public static bool HasValidTimestamp(this TableStorageEntity entity)
        {
            return entity.Timestamp > TableStorageConstants.MinSupportedDateTime;
        }
    }
}